<template>
  <div class="menu-list">
    <div
        class="menu-item"
        v-for="item in menus"
        :key="item.menuCode"
        @click="handleClick(item.id)"
        :class="{ active: item.id === activeId }" >
      <el-icon :size="24" class="icon">
        <component :is="item.icon" />
      </el-icon>
      <div class="text">{{ item.name }}</div>
    </div>
  </div>
</template>

<script setup>
import { HomeFilled, Share, DeleteFilled } from '@element-plus/icons-vue';
import { useRouter } from 'vue-router';
import {ref} from "vue";

const router = useRouter();

const activeId = ref(1);
const menus = [
  {
    id:1,
    icon: HomeFilled,
    name: "首页",
    menuCode: "main",
    path: "/main/all",
    allShow: true,
  },
  {
    id:2,
    icon: Share,
    name: "分享",
    menuCode: "share",
    path: "/main/share",
    allShow: true,
  },
  {
    id:3,
    icon: DeleteFilled,
    name: "回收站",
    menuCode: "recycle",
    path: "/main/recycle",
    allShow: true,
  },
];

const emit = defineEmits(['menuSelected']);
const handleClick = (id) => {
  activeId.value = id;
  console.log("ssss",activeId.value);
  emit('menuSelected', id); // 触发事件并传递数据
};
</script>

<style scoped lang="scss">
.menu-list {
  height: calc(100vh - 56px);
  width: 80px;
  box-shadow: 0 3px 10px 0 rgb(0 0 0 / 6%);
  border-right: 1px solid #f1f2f4;
  .menu-item {
    text-align: center;
    font-size: 16px; /* Increased font size */
    font-weight: bold;
    padding: 15px 0; /* Adjusted padding for better spacing */
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    &:hover {
      background: #f3f3f3;
    }
    .icon {
      margin-bottom: 4px; /* Reduced margin between icon and text */
    }
    .text {
      font-size: 16px; /* Increased font size */
      font-weight: bold;
    }
  }

  &.active {
    background: #851537 !important; /* Background color for active item */
    .icon {
      color: #06a7ff !important ; /* Icon color for active item */
    }
    .text {
      color: #06a7ff !important; /* Text color for active item */
    }
  }
}
.menu-item.active {
  background: #F2FAFF;
  .icon {
    color: #06a7ff;
  }
  .text {
    color: #06a7ff;
  }
}
</style>
